package cn.bdqn.controller.sys;

import cn.bdqn.entity.SignImage;
import cn.bdqn.service.sys.SysSignService;
import cn.bdqn.utils.MyLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @ProjectName: ycbdqn
 * @Package: cn.bdqn.controller.sys
 * @Author: huat
 * @Date: 2020/3/12 10:27
 * @Version: 1.0
 */
@Controller
@RequestMapping("/sys/sign")
public class SysSignController {
    @Autowired
    SysSignService sysSignService;
    /**
     * 进入活动页面
     */
    @RequestMapping("intoSign")
    public String intoSign(){
        return "sign/sign";
    }

    /**
     * 查询活动
     * @param page 起始页
     * @param limit 页面大小
     * @param signName  活动名称
     * @return
     */
    @RequestMapping("getSign")
    @MyLog("查询活动")
    @ResponseBody
    public Map<String,Object> getSign(int page,int limit,String signName){
        return sysSignService.getSign(page, limit, signName);
    }

    /**
     * 通过活动id删除活动
     * @param signId
     * @return
     */
    @RequestMapping("deleteSign")
    @ResponseBody
    @MyLog("删除轮播图")
    public boolean deleteSign(int signId){
        return sysSignService.deleteSign(signId);
    }

    /**
     * 根据id查询活动
     * @param signId 活动id
     * @param type 查询
     * @return
     */
    @RequestMapping("getSignById")
    @MyLog("根据id查询轮播图")
    public String getSignById(int signId, String type, Model model){
        model.addAttribute("sign",sysSignService.getSignById(signId));
        return "sign/updateSign";

    }

    /**
     * 修改活动图
     * @param request
     * @param signImage
     * @return
     */
    @RequestMapping("updateSign")
    @ResponseBody
    @MyLog("修改活动图")
    public String updateSign(HttpServletRequest request,SignImage signImage){
        return sysSignService.updateSign(request, signImage);
    }

    /**
     * 进入添加活动页面
     * @return
     */
    @RequestMapping("intoAddSign")
    public String intoAddSign(){
        return "sign/addSign";
    }

    /**
     * 添加活动
     * @param request
     * @param signImage 活动对象
     * @return
     */
    @RequestMapping("addSign")
    @ResponseBody
    @MyLog("添加活动")
    public String addSign(HttpServletRequest request,SignImage signImage){
        return sysSignService.addSign(request, signImage);
    }
}
